home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / select-to-image.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-06-30  |  2.7 KB  |  80 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Selection to Image
  4. ; Copyright (c) 1997 Adrian Likins
  5. ; aklikins@eos.ncsu.edu
  6. ;
  7. ; Takes the Current selection and saves it as a seperate image.
  8. ;
  9. ;
  10. ; This program is free software; you can redistribute it and/or modify
  11. ; it under the terms of the GNU General Public License as published by
  12. ; the Free Software Foundation; either version 2 of the License, or
  13. ; (at your option) any later version.
  14. ; This program is distributed in the hope that it will be useful,
  15. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ; GNU General Public License for more details.
  18. ; You should have received a copy of the GNU General Public License
  19. ; along with this program; if not, write to the Free Software
  20. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.  
  23. (define (script-fu-selection-to-image image drawable)
  24.   (let* ((draw-type (car (gimp-drawable-type-with-alpha drawable)))
  25.      (image-type (car (gimp-image-base-type image)))
  26.      (selection-bounds (gimp-selection-bounds image))
  27.      (select-offset-x  (cadr selection-bounds))
  28.      (select-offset-y  (caddr selection-bounds))
  29.      (selection-width  (- (cadr (cddr selection-bounds)) select-offset-x))
  30.      (selection-height (- (caddr (cddr selection-bounds)) select-offset-y)))
  31.  
  32.     (gimp-context-push)
  33.  
  34.     (gimp-image-undo-disable image)
  35.     
  36.     (if (= (car (gimp-selection-is-empty image)) TRUE)
  37.     (begin
  38.       (gimp-selection-layer-alpha drawable)
  39.       (set! active-selection (car (gimp-selection-save image)))
  40.       (set! from-selection FALSE))
  41.     (begin
  42.       (set! from-selection TRUE)
  43.       (set! active-selection (car (gimp-selection-save image)))))
  44.  
  45.     (gimp-edit-copy drawable)
  46.  
  47.     (set! new-image (car (gimp-image-new selection-width
  48.                      selection-height image-type)))
  49.     (set! new-draw (car (gimp-layer-new new-image
  50.                     selection-width selection-height
  51.                     draw-type "Selection" 100 NORMAL-MODE)))
  52.     (gimp-image-add-layer new-image new-draw 0)
  53.     (gimp-drawable-fill new-draw BACKGROUND-FILL)
  54.  
  55.     (let ((floating-sel (car (gimp-edit-paste new-draw FALSE))))
  56.       (gimp-floating-sel-anchor floating-sel))
  57.  
  58.     (gimp-image-undo-enable image)
  59.     (gimp-image-set-active-layer image drawable)
  60.     (gimp-display-new new-image)
  61.     (gimp-displays-flush)
  62.  
  63.     (gimp-context-pop)))
  64.  
  65. (script-fu-register "script-fu-selection-to-image"
  66.             _"To _Image"
  67.             "Convert a selection to an image"
  68.             "Adrian Likins <adrian@gimp.org>"
  69.             "Adrian Likins"
  70.             "10/07/97"
  71.             "RGB* GRAY*"
  72.             SF-IMAGE    "Image"    0
  73.             SF-DRAWABLE "Drawable" 0)
  74.  
  75. (script-fu-menu-register "script-fu-selection-to-image"
  76.              _"<Image>/Script-Fu/Selection")
  77.